//
//  CityPaysViewController.m
//  cityStar
//
//  Created by joyban on 15-1-23.
//  Copyright (c) 2015年 tiny. All rights reserved.
//

#import "CityPaysViewController.h"
#import "HTDefine.h"
#import "merchantListCell.h"
#import "RepairAndHomeViewController.h"

NSString *const merchantCityListTableViewCellID = @"merchantCityListTableViewCellID";

@interface CityPaysViewController ()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextField *shopNameText;
@property (weak, nonatomic) IBOutlet UITextField *shopPrcetext;
@property (weak, nonatomic) IBOutlet UITableView *CityPayTabelView;
@property (weak, nonatomic) IBOutlet UIView *heardView;

@end

@implementation CityPaysViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpTableViews];
    
    [self.view endEditing:YES];
    
    self.shopPrcetext.returnKeyType =UIReturnKeyDone;
    self.shopNameText.returnKeyType =UIReturnKeyDone;
    self.shopNameText.delegate = self;
    self.shopPrcetext.delegate = self;
    
    self.CityPayTabelView.tableHeaderView = self.heardView;
    
    self.navigationItem.title = @"银联快付";
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 90, 30)];
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftButton setFrame:CGRectMake(-30, 0, 90, 30)];
    [leftButton setTitle:@"返回" forState:UIControlStateNormal];
    leftButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [leftButton setTitleColor:[UIColor colorWithWhite:0.200 alpha:1.000] forState:UIControlStateNormal];
    [leftButton setTitleColor:[UIColor colorWithRed:0.991 green:0.532 blue:0.303 alpha:1.000] forState:UIControlStateHighlighted];
    [leftButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [leftButton setImage:[UIImage imageNamed:@"back_touch"] forState:UIControlStateHighlighted];
    
    [view addSubview:leftButton];
    
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:view];
    self.navigationItem.leftBarButtonItem = barButtonItem;
}

-(void)setUpTableViews
{
    [self.CityPayTabelView registerNib:[merchantListCell nib] forCellReuseIdentifier:merchantCityListTableViewCellID];
}

-(void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewWillAppear:(BOOL)animated
{
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >=7.0) {
        self.navigationController.navigationBar.translucent = NO; //禁止半透明毛玻璃效果
        self.navigationController.navigationBar.tintColor = kWhiteNavTitleColor; //返回按钮颜色
        self.navigationController.navigationBar.barTintColor = [UIColor whiteColor]; //bar背景颜色
        self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:kWhiteNavTitleColor,NSFontAttributeName:[UIFont boldSystemFontOfSize:18]}; //标题颜色
        self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    }else{
        [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]]; //bar背景颜色
        self.navigationController.navigationBar.translucent = NO;
        self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:kWhiteNavTitleColor,NSFontAttributeName:[UIFont boldSystemFontOfSize:18]};
        self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    }
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.shopNameText resignFirstResponder];
    [self.shopPrcetext resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [merchantListCell heightOfTableCell];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

#pragma mark - UITableViewDataSource
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    merchantListCell *ListdetailCell = [tableView dequeueReusableCellWithIdentifier:merchantCityListTableViewCellID];
    ListdetailCell.selectionStyle = UITableViewCellSelectionStyleGray;
    return ListdetailCell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView reloadData];
    RepairAndHomeViewController *HomeController = [[RepairAndHomeViewController alloc]init];
    [self.navigationController pushViewController:HomeController animated:YES];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
